package com.phpxiu.app.adapter.holder;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.push.Foreground;
import com.phpxiu.app.view.custom.FrescoImageView;

/**
 * Created by WuJinZhou on 2016/5/30.
 */
public class RoomFansRankViewHolder {
    private final static ForegroundColorSpan SPAN=new ForegroundColorSpan(Color.parseColor("#ffFF6680"));
    public ImageView rankIconView;
    public TextView rankView;
    public FrescoImageView avatarView;
    public TextView nickView;
    public ImageView sexIconView;
    public FrescoImageView lvIconView;
    public TextView ticketsCountView;//粉丝贡献累计值
    public View divider;
    private SpannableStringBuilder ticketsTxt=new SpannableStringBuilder();
    public RoomFansRankViewHolder(View itemView) {
        rankIconView=(ImageView)itemView.findViewById(R.id.rank_icon_view);
        rankView=(TextView)itemView.findViewById(R.id.rank_text_view);
        avatarView=(FrescoImageView)itemView.findViewById(R.id.avatar_view);
        nickView=(TextView)itemView.findViewById(R.id.nick_view);
        sexIconView=(ImageView)itemView.findViewById(R.id.fans_sex_icon);
        lvIconView=(FrescoImageView)itemView.findViewById(R.id.fans_lv_icon);
        ticketsCountView=(TextView)itemView.findViewById(R.id.tickets_count_view);
        divider=itemView.findViewById(R.id.divider_view);
    }

    public void setRank(int rank){
        if(rank<3){
            if(rankView.getVisibility()==View.VISIBLE){
                rankView.setVisibility(View.INVISIBLE);
            }
            if(rankIconView.getVisibility()!=View.VISIBLE){
                rankIconView.setVisibility(View.VISIBLE);
            }
        }else{
            if(rankView.getVisibility()!=View.VISIBLE){
                rankView.setVisibility(View.VISIBLE);
            }
            if(rankIconView.getVisibility()==View.VISIBLE){
                rankIconView.setVisibility(View.INVISIBLE);
            }
        }
        switch (rank){
            case 0://第一名
                rankIconView.setImageResource(R.mipmap.fans_rank_no1);
                break;
            case 1://第二名
                rankIconView.setImageResource(R.mipmap.fans_rank_no2);
                break;
            case 2://第三名
                rankIconView.setImageResource(R.mipmap.fans_rank_no3);
                break;
            default://第四名及之后
                rankView.setText((rank+1)+"");
                break;
        }
    }
    /**
     * 设置礼券数
     * @param prefix
     * @param count
     */
    public void setTicketsCountView(String prefix,String count,String unit){
        ticketsTxt.clear();
        ticketsTxt.append(prefix).append(" ").append(count).append(" ").append(unit);
        int start=prefix.length()+1;
        int end=start+count.length();
        ticketsTxt.setSpan(SPAN,start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ticketsCountView.setText(ticketsTxt);
    }

    public void hideDivider(){
        if(divider.getVisibility()==View.VISIBLE){
            divider.setVisibility(View.INVISIBLE);
        }
    }

    public void showDivider(){
        if(divider.getVisibility()!=View.VISIBLE){
            divider.setVisibility(View.VISIBLE);
        }
    }
}
